import json
import os
import re
import time

from sympy.physics.units import force

from basepage.BasePage import BasePage
from utils.log import LoggerUtils
from utils.send_error_feishu import send_message

failure_record_file = 'failure_record.json'
def read_failure_record():
    if os.path.exists(failure_record_file):
        with open(failure_record_file, 'r') as file:
            return json.load(file).get('last_failed_index', 1)
    return 1

def write_failure_record(index):
    with open(failure_record_file, 'w') as file:
        json.dump({'last_failed_index': index}, file)

failure_record_file1 = 'failure_record1.json'
def read_failure_record1():
    if os.path.exists(failure_record_file1):
        with open(failure_record_file1, 'r') as file:
            return json.load(file).get('last_failed_index', 0)
    return 0

def write_failure_record1(index):
    with open(failure_record_file1, 'w') as file:
        json.dump({'last_failed_index': index}, file)

def reset_json():
    write_failure_record1(0)

class 针织连衣裙Page(BasePage):

    def __init__(self, page):
        super().__init__(page)



    def 连衣裙_针织连衣裙(self):

        self.goto("http://localhost:5173/home")

        # 点击快捷设计
        self.page.get_by_role("menuitem", name="快捷设计").click(force=True)
        # 点击创意组合
        self.click_locator(
            "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
            force=True)
        # 获取所有的分页数
        numb = int(self.locator('//li[@class="number"]', num=6).inner_text())
        LoggerUtils().logger().info(f'全部分页数：========== {numb}')
        start_num = read_failure_record()
        self.wait_for_timeout(100)
        # 循环所有的页数
        for j in range(start_num, 1500):
                     # 每页循环10款
            run_num = read_failure_record1()
            for i in range(run_num, 4):
                start_time = time.time()
                # 点击款式
                self.click_locator(f'[id="\\3{i} "]')
                if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                    self.wait_for_timeout(500)
                try:
                    if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                        self.wait_for_timeout(1000)
                    add_button = self.page.locator("//span[text()='您还没有添加装饰件']")
                    add_button.wait_for(timeout=500, state='visible')
                except Exception:
                    self.wait_for_timeout(4000)
                    num = self.page.locator('//div[@class="flex justify-between items-center"]').count()
                    # 检查是否包含 "袖口"，并调整 num 的值
                    adjusted_num = num
                    for q in range(1, num + 1):
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=q).inner_text()
                        if '袖口' in result:
                            adjusted_num -= 1
                    for a in range(1, adjusted_num + 1):
                        # 先取到所有的部件名称数和量
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=a).inner_text()
                        print('---------------------', result)
                        pattern = r'（(\d+)）'
                        match = re.search(pattern, result)
                        mover = int(match.group(1))
                        # 如果部件的数量大于1，就点击对应的查看更多
                        if mover > 1:
                            self.click_locator('//span[@class="el-text el-text--primary pointer"]', num=a)
                            self.wait_for_timeout(200)
                            for f in range(2, mover + 2):
                                text = self.locator('//span[@class="product-title text-base truncate ..."]', num=f).inner_text()
                                print(f'部件名称：========== {text}')
                                self.click_get_by_title(f"{text}", exact=True,force=False)


                                if self.page.query_selector('//div[@class="el-loading-spinner"]'):
                                    self.wait_for_timeout(100)
                                self.page.wait_for_selector('//div[@class="el-loading-spinner"]', state="hidden")
                                self.wait_for_timeout(500)
                                self.click_locator("span:nth-child(5)", force=False)
                                self.wait_for_timeout(600)
                            # self.wait_for_timeout(1000)
                            self.click_locator('//i[@class="el-icon relative top-1"]')
                            self.wait_for_timeout(800)
                            self.browser_浏览器操作(reload=True)
                            self.wait_for_timeout(800)

                finally:

                    # 获取当前的url,以确定款号

                    LoggerUtils().logger().info(f'{self.page.url}')

                    # 点击选择灵感
                    self.wait_for_timeout(1000)
                    self.click_get_by_role(role_name=("tab", '1 选择灵感'), force=True)

                    try:

                        add_button = self.page.get_by_role(role="button", name='取消')

                        add_button.wait_for(timeout=500, state='visible')

                        LoggerUtils().logger().info("定位到取消按钮")

                        add_button.click()

                        self.wait_for_timeout(200)

                        # 点击创意组合
                        self.click_locator(
                            "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                            force=True)

                        self.browser_浏览器操作(reload=True)

                        # self.page.wait_for_timeout(500)

                        self.wait_for_timeout(200)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        write_failure_record1(i)
                        write_failure_record(j)
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")

                    except Exception:
                        # 点击创意组合
                        try:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)
                        except Exception:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)

                        self.browser_浏览器操作(reload=True)

                        # self.wait_for_timeout(200)

                        self.wait_for_timeout(500)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        # 跳转到指定的页数

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")
                        write_failure_record1(i)
                        write_failure_record(j)
            reset_json()
            for i in range(0, 2):
                start_time = time.time()
                # 点击款式
                self.click_locator(f"[id=\"\\31 {i}\"]",force=True)
                # 等待加载模型三秒
                # self.page.wait_for_timeout(4500)
                if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                    self.wait_for_timeout(500)
                try:
                    if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                        self.wait_for_timeout(1000)
                    add_button = self.page.locator("//span[text()='您还没有添加装饰件']")
                    add_button.wait_for(timeout=500, state='visible')
                except Exception:

                    self.wait_for_timeout(4000)
                    num = self.page.locator('//div[@class="flex justify-between items-center"]').count()
                    # 检查是否包含 "袖口"，并调整 num 的值
                    adjusted_num = num
                    for q in range(1, num + 1):
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=q).inner_text()
                        if '袖口' in result:
                            adjusted_num -= 1
                    for a in range(1, adjusted_num + 1):
                        # 先取到所有的部件名称数和量
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=a).inner_text()
                        print('---------------------', result)
                        pattern = r'（(\d+)）'
                        match = re.search(pattern, result)
                        mover = int(match.group(1))
                        # 如果部件的数量大于1，就点击对应的查看更多
                        if mover > 1:
                            self.click_locator('//span[@class="el-text el-text--primary pointer"]', num=a)
                            self.wait_for_timeout(1000)
                            for f in range(2, mover + 2):
                                text = self.locator('//span[@class="product-title text-base truncate ..."]', num=f).inner_text()
                                print(f'部件名称：========== {text}')
                                self.click_get_by_title(f"{text}", exact=True)
                                if self.page.query_selector('//div[@class="el-loading-spinner"]'):
                                    self.wait_for_timeout(100)
                                self.page.wait_for_selector('//div[@class="el-loading-spinner"]', state="hidden")
                                self.wait_for_timeout(200)
                                self.click_locator("span:nth-child(5)", force=True)
                                self.wait_for_timeout(600)

                            self.click_locator('//i[@class="el-icon relative top-1"]')
                            self.wait_for_timeout(800)
                            self.browser_浏览器操作(reload=True)
                            self.wait_for_timeout(800)


                finally:

                    # 获取当前的url,以确定款号

                    LoggerUtils().logger().info(f'{self.page.url}')

                    # 点击选择灵感
                    self.wait_for_timeout(1000)
                    self.click_get_by_role(role_name=("tab", '1 选择灵感'), force=True)

                    try:

                        add_button = self.page.get_by_role(role="button", name='取消')

                        add_button.wait_for(timeout=500, state='visible')

                        LoggerUtils().logger().info("定位到取消按钮")

                        add_button.click()

                        self.wait_for_timeout(200)


                        self.click_locator(
                            "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                            force=True)

                        self.browser_浏览器操作(reload=True)

                        self.page.wait_for_timeout(500)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        # 跳转到指定的页数

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")

                    except Exception:
                        # 点击创意组合
                        try:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)
                        except Exception:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)

                        self.browser_浏览器操作(reload=True)

                        # self.page.wait_for_timeout(200)


                        self.wait_for_timeout(500)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        # 跳转到指定的页数

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")
                        write_failure_record(j)



    def 连衣裙_针织连衣裙1(self):
        # 点击快捷设计
        self.page.get_by_role("menuitem", name="快捷设计").click(force=True)
        # 点击创意组合
        self.click_locator(
            "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
            force=True)
        # 获取所有的分页数
        numb = int(self.locator('//li[@class="number"]', num=6).inner_text())
        LoggerUtils().logger().info(f'全部分页数：========== {numb}')
        start_num = read_failure_record()
        self.wait_for_timeout(100)
        # 循环所有的页数
        for j in range(150, 160):
                     # 每页循环10款
            run_num = read_failure_record1()
            for i in range(0, 10):
                start_time = time.time()
                # 点击款式
                self.click_locator(f'[id="\\3{i} "]')
                if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                    self.wait_for_timeout(500)
                try:
                    if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                        self.wait_for_timeout(1000)
                    add_button = self.page.locator("//span[text()='您还没有添加装饰件']")
                    add_button.wait_for(timeout=500, state='visible')
                except Exception:
                    self.wait_for_timeout(4000)
                    num = self.page.locator('//div[@class="flex justify-between items-center"]').count()
                    # 检查是否包含 "袖口"，并调整 num 的值
                    adjusted_num = num
                    for q in range(1, num + 1):
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=q).inner_text()
                        if '袖口' in result:
                            adjusted_num -= 1
                    for a in range(1, adjusted_num + 1):
                        # 先取到所有的部件名称数和量
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=a).inner_text()
                        print('---------------------', result)
                        pattern = r'（(\d+)）'
                        match = re.search(pattern, result)
                        mover = int(match.group(1))
                        # 如果部件的数量大于1，就点击对应的查看更多
                        if mover > 1:
                            self.click_locator('//span[@class="el-text el-text--primary pointer"]', num=a)
                            self.wait_for_timeout(200)
                            for f in range(2, mover + 2):
                                text = self.locator('//span[@class="product-title text-base truncate ..."]', num=f).inner_text()
                                print(f'部件名称：========== {text}')
                                self.click_get_by_title(f"{text}", exact=True)


                                if self.page.query_selector('//div[@class="el-loading-spinner"]'):
                                    self.wait_for_timeout(100)
                                self.page.wait_for_selector('//div[@class="el-loading-spinner"]', state="hidden")
                                self.wait_for_timeout(500)
                                self.click_locator("span:nth-child(5)", force=True)
                                self.wait_for_timeout(600)
                            # self.wait_for_timeout(1000)
                            self.click_locator('//i[@class="el-icon relative top-1"]')
                            self.wait_for_timeout(800)
                            self.browser_浏览器操作(reload=True)
                            self.wait_for_timeout(800)

                finally:

                    # 获取当前的url,以确定款号

                    LoggerUtils().logger().info(f'{self.page.url}')

                    # 点击选择灵感
                    # self.wait_for_timeout(1000)
                    self.click_get_by_role(role_name=("tab", '1 选择灵感'), force=True)

                    try:

                        add_button = self.page.get_by_role(role="button", name='取消')

                        add_button.wait_for(timeout=500, state='visible')

                        LoggerUtils().logger().info("定位到取消按钮")

                        add_button.click()

                        self.wait_for_timeout(200)

                        # 点击创意组合
                        self.click_locator(
                            "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                            force=True)

                        self.browser_浏览器操作(reload=True)

                        # self.page.wait_for_timeout(500)

                        self.wait_for_timeout(200)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        write_failure_record1(i)
                        write_failure_record(j)
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")

                    except Exception:
                        # 点击创意组合
                        try:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)
                        except Exception:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)

                        self.browser_浏览器操作(reload=True)

                        # self.wait_for_timeout(200)

                        self.wait_for_timeout(500)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        # 跳转到指定的页数

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")
                        write_failure_record1(i)
                        write_failure_record(j)
            reset_json()
            for i in range(0, 2):
                start_time = time.time()
                # 点击款式
                self.click_locator(f"[id=\"\\31 {i}\"]",force=True)
                # 等待加载模型三秒
                # self.page.wait_for_timeout(4500)
                if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                    self.wait_for_timeout(500)
                try:
                    if self.page.wait_for_selector('//div[@class="el-loading-spinner"]'):
                        self.wait_for_timeout(1000)
                    add_button = self.page.locator("//span[text()='您还没有添加装饰件']")
                    add_button.wait_for(timeout=500, state='visible')
                except Exception:

                    self.wait_for_timeout(4000)
                    num = self.page.locator('//div[@class="flex justify-between items-center"]').count()
                    # 检查是否包含 "袖口"，并调整 num 的值
                    adjusted_num = num
                    for q in range(1, num + 1):
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=q).inner_text()
                        if '袖口' in result:
                            adjusted_num -= 1
                    for a in range(1, adjusted_num + 1):
                        # 先取到所有的部件名称数和量
                        result = self.locator('//div[@class="flex justify-between items-center"]', num=a).inner_text()
                        print('---------------------', result)
                        pattern = r'（(\d+)）'
                        match = re.search(pattern, result)
                        mover = int(match.group(1))
                        # 如果部件的数量大于1，就点击对应的查看更多
                        if mover > 1:
                            self.click_locator('//span[@class="el-text el-text--primary pointer"]', num=a)
                            self.wait_for_timeout(1000)
                            for f in range(2, mover + 2):
                                text = self.locator('//span[@class="product-title text-base truncate ..."]', num=f).inner_text()
                                print(f'部件名称：========== {text}')
                                self.click_get_by_title(f"{text}", exact=True)
                                if self.page.query_selector('//div[@class="el-loading-spinner"]'):
                                    self.wait_for_timeout(100)
                                self.page.wait_for_selector('//div[@class="el-loading-spinner"]', state="hidden")
                                self.wait_for_timeout(200)
                                self.click_locator("span:nth-child(5)", force=True)
                                self.wait_for_timeout(600)

                            self.click_locator('//i[@class="el-icon relative top-1"]')
                            self.wait_for_timeout(800)
                            self.browser_浏览器操作(reload=True)
                            self.wait_for_timeout(800)


                finally:

                    # 获取当前的url,以确定款号

                    LoggerUtils().logger().info(f'{self.page.url}')

                    # 点击选择灵感

                    self.click_get_by_role(role_name=("tab", '1 选择灵感'), force=True)

                    try:

                        add_button = self.page.get_by_role(role="button", name='取消')

                        add_button.wait_for(timeout=500, state='visible')

                        LoggerUtils().logger().info("定位到取消按钮")

                        add_button.click()

                        self.wait_for_timeout(200)


                        self.click_locator(
                            "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                            force=True)

                        self.browser_浏览器操作(reload=True)

                        self.page.wait_for_timeout(500)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        # 跳转到指定的页数

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")

                    except Exception:
                        # 点击创意组合
                        try:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)
                        except Exception:
                            self.click_locator(
                                "//div[@class='el-row is-justify-space-between my-20']//div[2]//div[1]//div[1]//div[1]//img[1]",
                                force=True)

                        self.browser_浏览器操作(reload=True)

                        # self.page.wait_for_timeout(200)


                        self.wait_for_timeout(500)

                        self.page.get_by_label("页", exact=True).fill(f"{j}")

                        LoggerUtils().logger().info(f"输入的页数:{j}")

                        # 跳转到指定的页数

                        self.page.get_by_label("页", exact=True).press("Enter")

                        LoggerUtils().logger().info(f"跳转的页数:{j}")
                        end_time = time.time()
                        send_message(f"跳转的页数:{j}，当前款式更换部件共耗时：{end_time - start_time:.3f}秒")
                        write_failure_record(j)
    # def 连衣裙_针织连衣裙1(self):
    #     # 点击快捷设计
    #     self.page.get_by_role("menuitem", name="快捷设计").click()
    #     # 点击创意组合
    #     self.click_locator('//*[@id="app"]/div/section/main/aside/div/div[2]/div/div/div/img',force=True)
    #     # 点击T恤
    #     self.click_get_by_role(role_name=('button', '连衣裙'),force=True)
    #     # 选择全部分类
    #     self.click_locator('//span[text()="全部 "]', num=1, force=True)
    #     # 点击修身分类
    #     self.page.wait_for_timeout(250)
    #     self.click_get_by_role(role_name=("menuitem", '针织连衣裙'), force=True)
    #     self.page.wait_for_timeout(250)
    #     # 获取所有的分页数
    #     numb = int(self.locator('//li[@class="number"]', num=6).inner_text())
    #     LoggerUtils().logger().info(f'全部分页数：========== {numb}')
    #     # 循环所有的页数
    #     for j in range(1, numb - 1):
    #         # 每页循环10款
    #         for i in range(0, 2):
    #             # 点击款式
    #             self.click_locator(f"[id=\"\\31 {i}\"]",force=True)
    #             # 等待加载模型三秒
    #             self.page.wait_for_timeout(4500)
    #             try:
    #                 add_button = self.page.locator("//span[text()='您还没有添加装饰件']")
    #                 add_button.wait_for(timeout=500, state='visible')
    #             except Exception:
    #                 # 如果 "添加" 按钮不可见或不存在，则点击 "查看更多"
    #
    #                 Collar_number = self.locator(
    #                     '//span[@class="title-num text-xl pl-[0.35rem] pr-[0.35rem]"]').inner_text()
    #                 pattern = r'（(\d+)）'
    #                 match = re.search(pattern, Collar_number)
    #                 number = int(match.group(1))
    #                 LoggerUtils().logger().info(f'领子的数量：========== {number}')
    #
    #                 # 点击领子更多
    #                 self.click_locator('//span[text()="查看更多"]', force=True)
    #                 # 循环所有的领子
    #                 for d in range(2, number + 2):
    #                     # 获取所有的领子名称
    #                     text = self.locator('//span[@class="product-title text-base truncate ..."]', num=d).inner_text()
    #                     print(f'部件名称：========== {text}')
    #                     # 将取到的领子名字赋值到元素定位方式里面
    #                     # self.get_by_title(f"{text}",exact=True).click(force=True)
    #                     self.click_get_by_title(f"{text}", exact=True, force=True)
    #
    #                     # 更换完领子之后等待加载
    #                     self.page.wait_for_timeout(2000)
    #                     self.click_locator("span:nth-child(5)", force=True)
    #                     self.page.wait_for_timeout(500)
    #                 #     点击领子返回上一级
    #                 self.click_get_by_text(f"{Collar_number}", force=True)
    #
    #                 # self.browser_浏览器操作(reload=True)
    #
    #                 Collar_number2 = self.locator('//span[@class="title-num text-xl pl-[0.35rem] pr-[0.35rem]"]',
    #                                               num=2).inner_text()
    #                 pattern = r'（(\d+)）'
    #                 match = re.search(pattern, Collar_number2)
    #                 number2 = int(match.group(1))
    #                 LoggerUtils().logger().info(f'袖子的数量：========== {number2}')
    #                 # 点击袖子
    #                 self.click_locator('//span[text()="查看更多"]', num=2, force=True)
    #
    #                 # 循环点击袖子
    #                 for d in range(2, number2 + 2):
    #                     # 获取所有的袖子名称
    #                     text = self.locator('//span[@class="product-title text-base truncate ..."]', num=d).inner_text()
    #                     print(f'部件名称：========== {text}')
    #                     # 将取到的领子名字赋值到元素定位方式里面
    #                     self.click_get_by_title(f"{text}", exact=True, force=True)
    #
    #                     # 更换完袖子之后等待加载
    #                     self.page.wait_for_timeout(2000)
    #                     self.click_locator("span:nth-child(5)", force=True)
    #                     self.page.wait_for_timeout(500)
    #
    #                 self.click_get_by_text(f"{Collar_number2}", force=True)
    #
    #
    #             finally:
    #
    #                 # 获取当前的url,以确定款号
    #
    #                 LoggerUtils().logger().info(f'{self.page.url}')
    #
    #                 # 点击选择灵感
    #
    #                 self.click_get_by_role(role_name=("tab", '1 选择灵感'), force=True)
    #
    #                 try:
    #
    #                     add_button = self.page.get_by_role(role="button", name='取消')
    #
    #                     add_button.wait_for(timeout=500, state='visible')
    #
    #                     LoggerUtils().logger().info("定位到取消按钮")
    #
    #                     add_button.click()
    #
    #                     self.page.wait_for_timeout(200)
    #
    #                     # 点击创意组合
    #
    #                     self.click_locator('//*[@id="app"]/div/section/main/aside/div/div[2]/div/div/div/img',
    #
    #                                        force=True)
    #
    #                     self.browser_浏览器操作(reload=True)
    #
    #                     self.page.wait_for_timeout(500)
    #
    #                     self.click_locator('//*[@id="app"]/div/section/main/aside/div/div[2]/div/div/div/img',
    #
    #                                        force=True)
    #
    #                     # 点击衬衫
    #
    #                     self.click_get_by_role(role_name=('button', '连衣裙'), force=True)
    #
    #                     self.page.wait_for_timeout(300)
    #
    #                     # 选择全部分类
    #
    #                     self.click_locator('//span[text()="全部 "]', num=1, force=True)
    #
    #                     # 点击修身分类
    #
    #                     self.click_get_by_role(role_name=("menuitem", '针织连衣裙'), force=True)
    #
    #                     self.page.wait_for_timeout(500)
    #
    #                     self.page.get_by_label("页", exact=True).fill(f"{j}")
    #
    #                     LoggerUtils().logger().info(f"输入的页数:{j}")
    #
    #                     # 跳转到指定的页数
    #
    #                     self.page.get_by_label("页", exact=True).press("Enter")
    #
    #                     LoggerUtils().logger().info(f"跳转的页数:{j}")
    #                     send_message(f"跳转的页数:{j}")
    #
    #                 except Exception:
    #
    #                     # 刷新浏览器页面
    #
    #                     # 点击创意组合
    #                     try:
    #                         self.click_locator('//*[@id="app"]/div/section/main/aside/div/div[2]/div/div/div/img',
    #                                            force=True)
    #                     except Exception:
    #                         self.click_locator('//*[@id="app"]/div/section/main/aside/div/div[2]/div/div/div/img',
    #                                            force=True)
    #
    #                     self.browser_浏览器操作(reload=True)
    #
    #                     self.page.wait_for_timeout(200)
    #
    #                     try:
    #                         self.click_locator('//*[@id="app"]/div/section/main/aside/div/div[2]/div/div/div/img',
    #                                            force=True)
    #                     except Exception:
    #                         self.click_locator('//*[@id="app"]/div/section/main/aside/div/div[2]/div/div/div/img',
    #                                            force=True)
    #
    #                     self.page.wait_for_timeout(500)
    #
    #                     # 点击T恤
    #
    #                     self.click_get_by_role(role_name=('button', '连衣裙'), force=True)
    #
    #                     self.page.wait_for_timeout(300)
    #
    #                     # 选择全部分类
    #                     try:
    #                         self.click_locator('//span[text()="全部 "]', num=1, force=True)
    #                     except Exception:
    #                         self.click_locator('//span[text()="全部 "]', num=1, force=True)
    #                     # 点击修身分类
    #                     self.click_get_by_role(role_name=("menuitem", '针织连衣裙'), force=True)
    #
    #                     self.page.wait_for_timeout(500)
    #
    #                     self.page.get_by_label("页", exact=True).fill(f"{j}")
    #
    #                     LoggerUtils().logger().info(f"输入的页数:{j}")
    #
    #                     # 跳转到指定的页数
    #
    #                     self.page.get_by_label("页", exact=True).press("Enter")
    #
    #                     LoggerUtils().logger().info(f"跳转的页数:{j}")
    #
    #                     send_message(f"跳转的页数:{j}")